<?php
/*
 * Copyright notice
 * 
 * (c) 2009 MH-Dev.de, Martin Hesse <info@mh-dev.de>
 * 
 * This script is part of the MH-Dev.-Board project. The MH-Dev.-Board 
 * is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, 
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU 
 * General Public License along with this program; if not, 
 * see http://www.gnu.org/licenses/.
 */


/**
 * View_Helper GetLastPost
 * 
 * @author	Martin Hesse <info@mh-dev.de>
 * @package	MH-Dev.-Board
 */
class MHDEV_View_Helper_GetLastPost extends Zend_View_Helper_Abstract
{
	/*
	 * Get some meta information about the last post in a thread
	 * 
	 * @param string $date_value Date in DATETIME-Format
	 * @param int $user_uid User-UID
	 * @param int $thread_uid Thread-UID
	 * 
	 * @return string translatet text
	 */
	public function GetLastPost($date_value, $user_uid, $thread_uid)
	{
		// lang
		$translate	= Zend_Registry::get('lang');
		
		// helper
		$date		= new MHDEV_View_Helper_Datetime();
		$author		= new MHDEV_View_Helper_GetAuthor();
		$url		= new Zend_View_Helper_Url();
		$base		= new MHDEV_View_Helper_BaseUrl();
		
		if($date != '0000-00-00 00:00:00')
		{
			$post_date		= $date->datetime($date_value,'dd. MMMM yy', true);
			$user_url		= $url->url(array('controller' => 'profile', 'uid' => $user_uid), 'profile', true);
			$last_post_url	= $url->url(array('controller' => 'posts', 'action' => 'getLastPost', 'uid' => $thread_uid), 'last_post', true);
			
			$username		= '<a href="' . $user_url . '">' . $author->GetAuthor($user_uid) . '</a>';
			$username		.= '&nbsp;<a href="' . $last_post_url . '"><img src="' . $base->BaseUrl() . '/static/gfx/last_post.gif" alt="' . $translate->_('topic_last_post_img') . '" title="' . $translate->_('topic_last_post_img') . '" /></a>';
			
			$values	= array('%date' => $post_date, '%user' => $username);
			return MHDEV_Sprintf($translate->_('topic_last_post'), $values);
		}
		else
		{
			return $translate->_('error_last_post');
		}
	}
}